home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / smaltalk / gnu_st.lha / gnu_st / smalltalk-1.1.1 / stix / Pen.st < prev    next >
Text File  |  1991-09-12  |  3KB  |  139 lines

  1. "======================================================================
  2. |
  3. | Copyright (C) 1990, 1991 Free Software Foundation, Inc.
  4. | Written by Steve Byrne.
  5. |
  6. | This file is part of GNU Smalltalk.
  7. |
  8. | GNU Smalltalk is free software; you can redistribute it and/or modify it
  9. | under the terms of the GNU General Public License as published by the Free
  10. | Software Foundation; either version 1, or (at your option) any later version.
  11. | GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
  12. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  13. | FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  14. | details.
  15. | You should have received a copy of the GNU General Public License along with
  16. | GNU Smalltalk; see the file COPYING.  If not, write to the Free Software
  17. | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
  18. |
  19.  ======================================================================"
  20.  
  21.  
  22. "
  23. |     Change Log
  24. | ============================================================================
  25. | Author       Date       Change 
  26. | sbyrne     24 May 90      created.
  27. |
  28. "
  29.  
  30. Object subclass: #Pen
  31.        instanceVariableNames: 'gc direction marking location'
  32.        classVariableNames: ''
  33.        poolDictionaries: ''
  34.        category: nil
  35. !
  36.  
  37.  
  38.  
  39. !Pen class methodsFor: 'instance creation'!
  40.  
  41. new: gc
  42.     ^super new init: gc
  43. !!
  44.  
  45.  
  46. !Pen methodsFor: 'accessing'!
  47.  
  48. direction
  49.     ^direction
  50. !
  51.  
  52. location
  53.     ^location
  54. !
  55.  
  56. gc
  57.     ^gc
  58. !!
  59.  
  60.  
  61.  
  62. !Pen methodsFor: 'moving'!
  63.  
  64. down
  65.     marking _ true
  66. !
  67.  
  68. up
  69.     marking _ false
  70. !
  71.  
  72. turn: degrees
  73.     direction _ direction + degrees
  74. !
  75.  
  76. north
  77.     direction _ 0
  78. !
  79.  
  80. go: distance
  81.     | dest dirRad |
  82.     dirRad _ direction degreesToRadians.
  83.     dest _ location + ((distance * dirRad sin) negated @ (distance * dirRad cos)).
  84.     self goto: dest rounded
  85. !
  86.  
  87. goto: aPoint
  88.     marking
  89.     ifTrue: [ gc polyLine: location to: aPoint coordMode: #Origin ].
  90.     location _ aPoint
  91. !
  92.  
  93.  
  94. place: aPoint
  95.     location _ aPoint
  96. !
  97.  
  98. home
  99.     location _ 0@0
  100. !!
  101.  
  102.  
  103. !Pen methodsFor: 'examples'!
  104.  
  105. spiral: n angle: a
  106.     1 to: n do:
  107.     [ :i | self go: i. 
  108.            self turn: a ]
  109. !
  110.  
  111. dragon: n
  112.     n = 0
  113.     ifTrue: [ self go: 10 ]
  114.     ifFalse:
  115.         [ n > 0
  116.           ifTrue:
  117.               [ self dragon: n - 1.
  118.             self turn: 90.
  119.             self dragon: 1 - n ]
  120.           ifFalse:
  121.               [ self dragon: -1 - n.
  122.             self turn: -90.
  123.             self dragon: 1 + n ] ]
  124. !!
  125.     
  126.  
  127.  
  128. !Pen methodsFor: 'private'!
  129.  
  130. init: aGC
  131.     marking _ false.
  132.     location _ 0@0.
  133.     direction _ 0.
  134.     gc _ aGC
  135. !!
  136.  
  137.